<?php

namespace app\modules\Order\controllers;

use Yii;
use app\modules\Order\models\OrderCustomer;
use app\modules\Order\models\OrderRoomCustomer;
use app\modules\Order\models\Order;
use app\modules\Order\models\OrderPrice;
use app\modules\Order\models\OrderPriceType;
use app\modules\Order\models\OrderAssign;
use app\modules\Order\models\Card;
use app\modules\Order\models\Excel;
use app\modules\Product\models\Product;
use app\modules\Order\models\OrderCustomerSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use Overtrue\Pinyin\Pinyin;
use yii\filters\AccessControl;
use app\modules\Cruise\models\Cruise;

/**
 * CustomerController implements the CRUD actions for OrderCustomer model.
 */
class CustomerController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
        ];
    }

//    public function actionExa()
//    {
//        $data = Cruise::find()->joinWith(['room'])->asArray()->all();
//        $objPHPExcel = new \PHPExcel();
//        $sheet = $objPHPExcel->getActiveSheet(0);
//        $sheet->setTitle('团队名单');
//        $sheet->getDefaultStyle()->getFont()->setSize(10)->setName('微软雅黑');
//        $sheet->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
//        $sheet->getDefaultColumnDimension()->setWidth(10);
//        $styleArray = [
//            'borders' => [
//                'allborders' => ['style'=>\PHPExcel_Style_Border::BORDER_THIN,'color'=>['argb'=>'000000']],
//            ],
//        ]; //设置border
//
//        $sheet->getStyle('A1:L1')->applyFromArray($styleArray);
//        $sheet->getStyle('A1:L1')->getAlignment()->setWrapText(true);
//        $sheet->getColumnDimension('A')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('B')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('C')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('D')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('E')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('F')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('G')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('H')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('I')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('J')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('K')->setWidth(15);// 设置宽度
//        $sheet->getColumnDimension('L')->setWidth(20);// 设置宽度
//
//        $sheet->getRowDimension(1)->setRowHeight(50);
//
//        $sheet->getStyle('A1:L1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('1C1C1C');
//        $sheet->getStyle('A1:L1')->getFont()->setSize(10)->setBold(true)->getColor()->setARGB('FFFAFA');
//
//
//        $titleArray = ['id','邮轮名称','舱房名称','简码','舱房类型','窗户','面积','阳台面积','入住人数','最少入住人数','楼层','状态'];
//        $sheet->fromArray($titleArray, NULL, 'A1');
//        $name = '';
//        $key = 0;
//        foreach ($data as $k => $v){
//            foreach ($v['room'] as $k1 => $v1){
//                switch ($v1['type']){
//                    case "1":
//                        $name = "内舱";break;
//                    case "2":
//                        $name =  "海景";break;
//                    case "3":
//                        $name =  "阳台";break;
//                    case "4":
//                        $name =  "普通套房";break;
//                    case "5":
//                        $name =  "高级套房";break;
//                    case "6":
//                        $name =  "其它";break;
//                    default: $name;
//                }
//                $ceil  = json_decode($v1['ceil']);
//
//
//                $sheet->setCellValue(sprintf("A%d", $key + 2), $v1['id']);
//                $sheet->setCellValue(sprintf("B%d", $key + 2), $v['name']);
//                $sheet->setCellValue(sprintf("C%d", $key + 2), $v1['name']);
//                $sheet->setCellValue(sprintf("D%d", $key + 2), $v1['code']);
//                $sheet->setCellValue(sprintf("E%d", $key + 2), $name);
//                $sheet->setCellValue(sprintf("F%d", $key + 2), $v1['windows']==1 ? "有窗" : "无窗");
//                $sheet->setCellValue(sprintf("G%d", $key + 2), $v1['area']);
//                $sheet->setCellValue(sprintf("H%d", $key + 2), $v1['balcony_area']);
//                $sheet->setCellValue(sprintf("I%d", $key + 2), $v1['num']);
//                $sheet->setCellValue(sprintf("J%d", $key + 2), $v1['min']);
//                $sheet->setCellValue(sprintf("K%d", $key + 2), !empty($ceil) ? implode(',', $ceil) : '(未设置)');
//                $sheet->setCellValue(sprintf("L%d", $key + 2), $v1['status']==1 ? "正常" : "禁用");
//
//                $key++;
//
//            }
//
//        }
//
//
//        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//        $fileName = sprintf("%s.xlsx",uniqid());
//        $path = 'uploads/excel/'.date('Ym').'/';
//        if(!is_dir($path)){
//            mkdir($path,0777,true);
//        }
//        $file = $path.$fileName;
//        $objWriter->save($file);
//        $file_name = '舱房信息';
//        header("Content-type: application/octet-stream");
//        header("Accept-Ranges: bytes");
//        header("Accept-Length: " . filesize($file));
//        header("Content-Disposition: attachment; filename=" .urlencode($file_name));
//        @readfile($file);
//
//    }




    /**
     * Lists all OrderCustomer models.
     * @return mixed
     */
    public function actionIndex($order_id)
    {
        if(empty($order_id)){
            return false;
        }
        //$this->layout = false;
        $searchModel = new OrderCustomerSearch();
        $dataProvider = $searchModel->search($order_id, Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'order_id' => $order_id,
        ]);
    }

    /**
     * Displays a single OrderCustomer model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

	// 审核护照
	public function actionPassportCheck(){//{{{

        //	OrderCustomer;
		$params = Yii::$app->request->get();
		
		$data = [];

		if($params && isset($params['OrderCustomer']['passport']) && !empty(trim($params['OrderCustomer']['passport'])) ){

			$params['OrderCustomer']['passport'] = trim($params['OrderCustomer']['passport']);

			$data = OrderCustomer::find()->where(['like','passport',$params['OrderCustomer']])
										 ->andWhere(['status'=>1])
										 //->andWhere(['status'=>1]) // 未过期的船期 Product->go_time  todo 
										 ->orderBy('passport_check')
										 ->all();

			// 从结果集中将 船期过期的客户去除
			foreach($data as $key=>$model){
				$day = date("Y-m-d");
				if($model->order->product['go_time'] < $day){
						
					var_dump($model->order->product['go_time']);
					unset($model);
				}
			}
		}
		
        return $this->render('passport-check', ['data'=>$data, 'params'=>$params]);
	}//}}}

	public function actionCheckSave(){//{{{

		$params = Yii::$app->request->get();
		
		$data = [];

		if($params && isset($params['passport_check']) && isset($params['id']) ){

			$model = $this->findModel($params['id']);

			$model->passport_check = $params['passport_check'];
			if($model->passport_check  == 2){ // 审核通过  变更类型为原件
				
				$model->passport_type = 1; 	// 变更为原件
				//$model->passport_type = 2;
			}
		
			$ret = $model->save();

			echo $ret;
		}else{
			echo false;
		}
	}//}}}


    /**
     * Creates a new OrderCustomer model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate($order_id)
    {
		$this->layout = '//empty';
        if(empty($order_id)){
            return false;
        }

        $model = new OrderCustomer();
		
        if ($model->load(Yii::$app->request->post()) && $model->save()) {

            return $this->redirect(['view', 'id' => $model->id]);
        }else{
            $model->order_id = $order_id;
            $model->status = 1;
            $model->passport_type = 1;
            $model->gender = 1;

            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

     /**
     *
     *  添加客户
     */
    public function actionCreateNew($order_id)
    {
        $this->layout = '//empty';
        if(empty($order_id)){
            return false;
        }

        $model = new OrderCustomer();
        $rc = new OrderRoomCustomer();
        $order = Order::findOne($order_id);

        if ($model->load(Yii::$app->request->post())) {
            
            if($model->save()){ // todo
               $customer_id = $model->id;
               $data = Yii::$app->request->get();
               $rc->order_id = $data['order_id'];
               $rc->order_room_id = $data['order_room_id'];
               $rc->customer_id = $customer_id;
               $rc->status = 1;
               $rc->price = $order->price;
               if($rc->save()){

                  //必选附加费
                  $orderPriceType = OrderPriceType::find()->where(['product_id'=>$order->product_id,'type'=>2])->all();
                  if($orderPriceType){
                    foreach($orderPriceType as $opt){
                        $orderPrice = OrderPrice::find()->where(['type'=>$opt->id,'order_id'=>$order->id])->one();
                        if($orderPrice){
                            $orderPrice->num = $orderPrice->num+1;
                            $customers = json_decode($orderPrice->customers);
                            array_push($customers,$customer_id);
                            $orderPrice->customers = $customers;
                            $orderPrice->save();
                        }else{
                            $orderPrice = new OrderPrice();
                            $orderPrice->desc = $opt->desc;
                            $orderPrice->price = $opt->price;
                            $orderPrice->num = 1;
                            $orderPrice->order_id = $order->id;
                            $orderPrice->type = $opt->id;
                            $customers = [$customer_id];
                            $orderPrice->customers = $customers;
                            $orderPrice->save();
                        }
                    }

                  }


                  return $this->redirect(Yii::$app->request->getReferrer());
               }

            }
            exit();
            return $this->redirect(['view', 'id' => $model->id]);
        }else{
            $model->order_id = $order_id;
            $model->status = 1;
            $model->passport_type = 1;
            $model->gender = 1;
            $model->nation = '汉';
            $model->country = '中国';

            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

    //生成名单
    public function actionCreateExcel($product_id,$template_id)
    {   
        //1 和 2 为 出境名单-北京 和天津
        $product = Product::findOne($product_id);


        if($template_id <= 2){

             //获取团队
            $assign = OrderAssign::find()->where(['product_id' => $product_id ,'status'=>1])->all();

            return $this->render("template_1",['product'=>$product,'template_id'=>$template_id,'assign'=>$assign]);

        }else if($template_id >=3 && $template_id <=6 || $template_id == 8 || $template_id == 9 || $template_id == 10 || $template_id == 11 || $template_id == 12 || $template_id == 13  || $template_id == 14){

            $type = 3; //全部订单
            $order_num = $people_num = 0; 

            $order_num = Order::find()->where(['product_id'=>$product_id])->andWhere(['<=','status',4])->count();
            $model = Order::find()->where(['product_id'=>$product_id])->andWhere(['<=','status',4])->all();

            foreach($model as $v){
                $people_num += $v->customerCount;
            }

            return $this->render("template_2",['product'=>$product,'template_id'=>$template_id,'type'=>$type,'order_num'=>$order_num,'people_num'=>$people_num]);
        }else if($template_id  = 7){
             //获取团队
            $assign = OrderAssign::find()->where(['product_id' => $product_id ,'status'=>1])->all();

            return $this->render("template_1",['product'=>$product,'template_id'=>$template_id,'assign'=>$assign]);
        }
    }

    //获取订单数量
    public function actionGetNum(){
        $data = yii::$app->request->get();
        if(empty($data)){
            return false;
        }
        $type = isset($data['type']) ? $data['type'] : '';
        $product_id = isset($data['product_id']) ? $data['product_id'] : '';

        $order_num = $people_num = 0; 

        if($type == 3){ //全部订单
            $order_num = Order::find()->where(['product_id'=>$product_id])->andWhere(['<=','status',4])->count();
            $model = Order::find()->where(['product_id'=>$product_id])->andWhere(['<=','status',4])->all();

            foreach($model as $v){
                $people_num += $v->customerCount;
            }
            print_r(json_encode(['order_num'=>$order_num,'people_num'=>$people_num]));
            exit();
        }else if($type == 2){ //已付款订单
            $order_num = Order::find()->where(['product_id'=>$product_id,'status'=>3])->count();
            $model = Order::find()->where(['product_id'=>$product_id,'status'=>3])->all();

            foreach($model as $v){
                $people_num += $v->customerCount;
            }
            print_r(json_encode(['order_num'=>$order_num,'people_num'=>$people_num]));
            exit();
 
        }else if($type == 1){ //已审核订单
            $order_num = Order::find()->where(['product_id'=>$product_id,'check'=>1])->andWhere(['<=','status',3])->count();
            $model = Order::find()->where(['product_id'=>$product_id,'check'=>1])->andWhere(['<=','status',3])->all();

            foreach($model as $v){
                $people_num += $v->customerCount;
            }
            print_r(json_encode(['order_num'=>$order_num,'people_num'=>$people_num]));
            exit();
        }else if($type == 4){ //已提交订单
            $order_num = Order::find()->where(['product_id'=>$product_id,'status'=>4])->count();
            $model = Order::find()->where(['product_id'=>$product_id,'status'=>4])->all();

            foreach($model as $v){
                $people_num += $v->customerCount;
            }
            print_r(json_encode(['order_num'=>$order_num,'people_num'=>$people_num]));
            exit();

        }
        print_r(json_encode(['order_num'=>$order_num,'people_num'=>$people_num]));

    }

    //创建Excel
    public function actionExcel(){

        $data = yii::$app->request->post();

        $excel = new Excel();
        $res = ['status' => 0 ,'msg'=> '' , 'data'=>''];
        if(empty($data)){
            print_r(json_encode($res));
        }

        

        $template_id = isset($data['template_id']) ? $data['template_id'] : '';
        $product_id = isset($data['product_id']) ? $data['product_id'] : '';
        $assign_arr = isset($data['assign_arr']) ? $data['assign_arr'] : '';
        $type = isset($data['type']) ? $data['type'] : '';

        $files = ['status'=>1,'msg'=>'','data'=>''];

        $model = Product::findOne($product_id);
        $zip = new \ZipArchive;//打包
        //打包文件名
        $filename = sprintf("%s.zip",uniqid()); 
        $file = $filename;
        $filename = str_replace("\"","",$filename); //删除双引号
        $filename = str_replace("'","",$filename);  //删除单引号
        $filename = str_replace("\\","",$filename); //删除斜杠
		$filename = str_replace("&","",$filename);  //删除&
        $filename = preg_replace("/\s/","",$filename); //去除空格
        //文件名
        $file_url_name = sprintf("%s_%s_%s的团队资料.zip",$model->name,date("Y年m月d日",strtotime($model->go_time)),yii::$app->params['template'][$data['template_id']]);
		$file_url_name = str_replace("\"","",$file_url_name); //删除双引号
		$file_url_name = str_replace("'","",$file_url_name);  //删除单引号
		$file_url_name = str_replace("\\","",$file_url_name); //删除斜杠
		$file_url_name = preg_replace("/\s/","",$file_url_name); //去除空格
		$file_url_name = str_replace("&","",$file_url_name);  //删除&
        $filename = sprintf("%s/web/uploads/zip/%s",Yii::$app->basePath,$filename);
        $filename = iconv("utf-8","gbk//ignore",$filename); //中文乱码
        $res = $zip->open($filename, \ZipArchive::OVERWRITE);//如果打包文件有就覆盖

        if($data['template_id'] == 1){ //模板北京

            if($assign_arr){
                if($res === TRUE) {
                    foreach($assign_arr as $v){
                        $res = $excel->Template1($product_id,$v['assign_id'],$v['lead_id']);
                        $down_url = iconv("utf-8","gbk//ignore",$res['down_url']); //中文乱码
                        $down_name = iconv("utf-8","gbk//ignore",$res['down_name']); //中文乱码
                        $zip->addFile($down_url,sprintf("%s.xlsx",$down_name));  
                    }
                    $zip->close();
                }   
            }
            $files['data'] = ['down_name'=>$file_url_name,'down_url'=>'uploads/zip/'.$file];    
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 2){

            
            if($assign_arr){
                if($res === TRUE) {
                    foreach($assign_arr as $v){
                        $res = $excel->Template2($product_id,$v['assign_id'],$v['lead_id']);
                        $down_url = iconv("utf-8","gbk//ignore",$res['down_url']); //中文乱码
                        $down_name = iconv("utf-8","gbk//ignore",$res['down_name']); //中文乱码
                        $zip->addFile($down_url,sprintf("%s.xlsx",$down_name));  
                    }
                    $zip->close();
                }   
            }
            $files['data'] = ['down_name'=>$file_url_name,'down_url'=>'uploads/zip/'.$file];   
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 7){
            if($assign_arr){
                if($res === TRUE) {
                    foreach($assign_arr as $v){
                        $res = $excel->Template7($product_id,$v['assign_id'],$v['lead_id']);
                        $down_url = iconv("utf-8","gbk//ignore",$res['down_url']); //中文乱码
                        $down_name = iconv("utf-8","gbk//ignore",$res['down_name']); //中文乱码
                        $zip->addFile($down_url,sprintf("%s.xlsx",$down_name));  
                    }
                    $zip->close();
                }   
            }
            $files['data'] = ['down_name'=>$file_url_name,'down_url'=>'uploads/zip/'.$file];
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 3){
            $zip->close();
            $files['data'] = $excel->Template3($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 4){
            $zip->close();
            $files['data'] = $excel->Template4($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 5){
            $zip->close();
            $files['data'] = $excel->Template5($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 6){
            $zip->close();
            $files['data'] = $excel->Template6($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 8){
            $zip->close();
            $files['data'] = $excel->Template8($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 9){
            $zip->close();
            $files['data'] = $excel->Template9($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 10){
            $zip->close();
            $files['data'] = $excel->Template10($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 11){
            $zip->close();
            $files['data'] = $excel->Template11($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 12){
            $zip->close();
            $files['data'] = $excel->Template12($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 13){
            $zip->close();
            $files['data'] = $excel->Template13($product_id,$type);
            print_r(json_encode($files));
            exit();
        }else if($data['template_id'] == 14){
            $zip->close();
            $files['data'] = $excel->Template14($product_id,$type);
            print_r(json_encode($files));
            exit();
        }

        print_r(json_encode($res));


    }

    //下载Excel文件
    public function actionDownloadFile($name,$url){
        $url = iconv("utf-8","gb2312",$url); 
        if(file_exists($url)){
            header("Content-type: application/octet-stream");    
            header("Accept-Ranges: bytes");    
            header("Accept-Length: " . filesize($url));    
            header("Content-Disposition: attachment; filename=" .urlencode($name));    
            @readfile($url);
            exit();
        }else{
            return false;
        }       

    }        
    
    //保存团号对应的领队ID
    public function actionSaveLeader($assign_id,$lead_id){
        if(empty($assign_id) || empty($lead_id)){
            return false;
        }
        $assign = OrderAssign::findOne($assign_id);
        $assign->leader_id = $lead_id;
        if($assign->save()){
             echo 1;
        }else{
             echo 0;
        }

    }
    
    /**
     * Updates an existing OrderCustomer model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $this->layout = '//empty';
        $model = $this->findModel($id);

		$data = Yii::$app->request->post();

		if(empty($data['OrderCustomer']['passport_img'])){
			unset($data['OrderCustomer']['passport_img']);
		}

		if(empty($data['OrderCustomer']['card_img'])){
			unset($data['OrderCustomer']['card_img']);
		}

        if ($model->load($data) && $model->save()) {

            return $this->redirect(Yii::$app->request->getReferrer());
            //return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Updates an existing OrderCustomer model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdateNew($id)
    {
        $this->layout = false;
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(Yii::$app->request->getReferrer());
            //return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }
	
	// 获取文字拼音
    public function actionPinyin(){//{{{

		$name = Yii::$app->request->get("name");

        $ret = Pinyin::trans($name,['accent'=>false]);

		print_r(str_replace(' ', '', strtoupper($ret)));
    }//}}}

	// 生成护照截止日期
	public function actionPassport(){//{{{
		
		$passport = Yii::$app->request->get("passport");
        $birthday = Yii::$app->request->get("birthday");

        $date = strtotime($passport);

        if($birthday){
            $age = $this->calcAge($birthday);
            if($age <= 18){
                $year2 = strtotime("+5 year", $date);   // 5年
                $day2 = strtotime("-1 day", $year2);      // 一天前
                print_r(date("Y-m-d", $day2));
                return false;
            }
        }
		

		$year = strtotime("+10 year", $date);	// 十年
		$day = strtotime("-1 day", $year);		// 一天前
		
		print_r(date("Y-m-d", $day));
	}//}}}

    //根据生日计算年龄
    private function  calcAge($birthday) {
        $age = 0;
        if(!empty($birthday)){
            $age = strtotime($birthday);
            if($age === false){
                return 0;
            }
            
            list($y1,$m1,$d1) = explode("-",date("Y-m-d", $age));
            
            list($y2,$m2,$d2) = explode("-",date("Y-m-d"), time());
            
            $age = $y2 - $y1;
            if((int)($m2.$d2) < (int)($m1.$d1)){
                $age -= 1;
            }
        }
        return $age;
   }

	// 根据身份证获取用户信息 [ 签发地, 性别, 出生日期, 出生地 ]
	public function actionCard(){//{{{
		\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;	

		$card = Yii::$app->request->get("card");
		// 1. 截取前六位  判断地区

		if($card){
			$area = substr($card, 0, 6); 
			$area2 = substr($card, 0, 3);
			
			$model = Card::find()->where(['card'=>$area])->one();
			$model2 = Card::find()->where([ 'card'=>sprintf("%d000",$area2) ])->one();

			if($model){
				$message['card_address'] = $model->area;
			}
			if($model2){
				$message['native'] = $model2->area;
			}

			$birthday = substr($card, 6, 8);
			$message['birthday'] = date("Y-m-d", strtotime($birthday));

			$gender = substr($card, 16, 1);
			if($gender%2 == 0){
				
				$message['gender'] = 2; // substr($card, 16, 1);
			}else{
			
				$message['gender'] = 1;
			}
		}
		//print_r(json_encode($message));
		return $message;
		
	}//}}}


    /**
     * Deletes an existing OrderCustomer model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

	//  获取指定用户信息
	public function actionGetMessage($id){//{{{
		$this->layout = false;

		$model = $this->findModel($id);

        return $this->render('detail', [
            'model' => $model,
        ]);


		if($model){
			print_r($model);
		}else{
			echo "";
		}
	}//}}}


   

    /**
     * Finds the OrderCustomer model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return OrderCustomer the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = OrderCustomer::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
